<?php
/**
 * CodeIgniter
 *
 * An open source application development framework for PHP 5.1.6 or newer
 *
 * @package		CodeIgniter
 * @author		ExpressionEngine Dev Team
 * @copyright	Copyright (c) 2008 - 2011, EllisLab, Inc.
 * @license		http://codeigniter.com/user_guide/license.html
 * @link		http://codeigniter.com
 * @since		Version 1.0
 * @filesource
 */

// ------------------------------------------------------------------------

/**
 * CodeIgniter String Helpers
 *
 * @package		CodeIgniter
 * @subpackage	Helpers
 * @category	Helpers
 * @author		ExpressionEngine Dev Team
 * @link		http://codeigniter.com/user_guide/helpers/string_helper.html
 */

// ------------------------------------------------------------------------

class Core_Helper_Array
{
	static function findHirechal($con, $list)
	{
		$result = array();
		if(is_array($con))
		foreach($list as $entry)
		{
			$find = true;
			if(is_array($con))
			foreach($con as $k => $v)
			{
				if($entry[$k]!==$v)
				$find = false;
			}
			if($find == true)
				$result[] = $entry;
			
			if(is_array(@$entry['children']))
				$result = array_merge($result, self::findHirechal($con, $entry['children']));
		}
		return $result;
	}
	/*
		Select2 plugin
		*/
	static function arrayHirechal($entries, $val, $key, $parent, $current = null)
	{
		$result = array();
		if(is_array($entries))
		foreach($entries as $entry)
		if($entry[$parent] == $current)	
		{
			$result[] = array(
				'id' => $entry[$key],
				'text' => $entry[$val],
				'children' => self::arrayHirechal($entries, $val, $key, $parent, $entry[$key]),
			);
		}
		return $result;
	}
	/*
		Zend View Helper
		formSelect(arrayOptions)
		*/
	static function arrayOptions($entries, $val, $key, $parent = null, $current = null)
	{
		$result = array();
		if(is_array($entries))
		foreach($entries as $entry)
		if(($parent == null)||($entry[$parent] == $current))
		{
			if($parent !== null)
				$childs = self::arrayOptions($entries, $val, $key, $parent, $entry[$key]);

			if(empty($childs))
				$result[$entry[$key]] = $entry[$val];
			else
				$result[$entry[$val]] = $childs;
		}
		return $result;
	}
	static function arraySort($entries, $key, $parent, $level = 0, $current = null)
	{
		$result = array();
		if(is_array($entries))
		foreach($entries as $entry)
		if($entry[$parent] == $current)	
		{
			$result = array_merge($result, array($entry+array('_level' => $level)), 
									self::arraySort($entries, $key, $parent, $level+1, $entry[$key]));
		}
		return $result;
	}
	static function arrayUnkey($entries, $key, $parent, $exclude, $add = array())
	{
		$result = array();
		$keylist = array();
		if(is_array($entries))
		{
			foreach($entries as $entry)
			{
				$keylist[$entry[$key]] = true;
			}
			foreach($entries as $entry)
			{
				if(!array_key_exists($entry[$parent], $keylist) && ($exclude!==$entry[$parent]))
				$result[] = array_merge($add, $entry);
			}
		}
		return $result;
	}
}

/* End of file string_helper.php */
/* Location: ./system/helpers/string_helper.php */